/*
 * Copyright (C) 2020 FoilPlanet
 *
 */

#ifndef _ANBOX_CODEC_AUDIO_SINK_H_
#define _ANBOX_CODEC_AUDIO_SINK_H_

#include "anbox/runtime.h"
#include "anbox/audio/sink.h"
#include "anbox/graphics/buffer_queue.h"

#include <thread>

namespace anbox {
namespace codec {

class AudioSink : public audio::Sink {
 public:
  AudioSink(const std::shared_ptr<anbox::Runtime> &runtime);

  ~AudioSink();

  void write_data(const std::vector<std::uint8_t> &data) override;

  bool is_connect() const {
    return false;
  };

 protected:
  void read_data(std::uint8_t *buffer, int size);

 private:
  bool connect_audio();
  void disconnect_audio();

  std::mutex lock_;
  graphics::BufferQueue queue_;
  graphics::Buffer read_buffer_;
  size_t read_buffer_left_ = 0;
};
} // namespace codec
} // namespace anbox

#endif /* _ANBOX_CODEC_AUDIO_SINK_H_ */
